package com.yl.chainStore.services.impl.pay

import com.yl.chainStore.entity.pay.PayCustomerOrder
import com.yl.chainStore.payrule.common.DiscountComputeOrderResultVo
import com.yl.chainStore.payrule.item.ItemRuleService
import com.yl.chainStore.services.pay.IItemRuleService
import com.yl.common.control.returnSuccess
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class ItemRuleServiceImpl() : IItemRuleService {

	companion object {
		private val log = LoggerFactory.getLogger(IItemRuleService::class.java)
	}

	@Autowired
	private lateinit var itemRules: List<ItemRuleService>

	override fun completeOrder(order: PayCustomerOrder): DiscountComputeOrderResultVo {
		log.info("项目优惠管理：==>: 执行订单：order:{}", order)
		var resOrder = order
		for (rules in itemRules) {
			val computeOrder = rules.computeOrder(order)
			resOrder = computeOrder.order
		}
		return DiscountComputeOrderResultVo(returnSuccess(), resOrder)
	}
}
